<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>单例模式</title>
</head>
<body>
  <button id="loginBtn">登陆</button>
  <script>
    // js的单例模式实现登陆
    let createLogin = function(){
      let div = document.createElement('div');
      div.innerHTML = '我是登陆的弹窗';
      div.style.display = 'none';
      document.body.appendChild(div)
      return div;
    }
    let getSingle = function(fn){
      let result;
      return function(){
        return result || (result==fn.apply(this,arguments))
      }
    }
    let create = getSingle(createLogin)
    document.getElementById('loginBtn').onclick = function(){
      let loginLay = create();
      loginLay.style.display = 'block'
    }
  </script>
</body>
</html>